import axios from '@/utils/axios';

export function getPreviewData(stationId, type = 1) {
  const params = {
    stationId,
    type
  }
  return axios.get('svg/realdata/previewStation', { params }).then(res => {
    if (res.code === 1) {
      return res.data;
    } else {
      throw res.msg;
    }
  })
}

/**
 * 查询设备列表
 * @author LXBsmile
 * @date 2019-11-12
 * @param {Object} params 请求参数对象
 * @param {Number} params.page 页码
 * @param {Number} params.rows 每页行数
 * @param {String} params.elementId 图元id
 * @param {Number} params.substationID 站点id
 * @param {Number} params.svgId 图形页面的id
 * @param {Number} params.devStatus 设备状态 1、良好；2、异常
 * @returns {Object}
 */
export function getDevsById(params) {
  return axios.get('plat/isp/queryDevInfoBySvg', { params }).then(res => {
    if (res.code === 1) return res.data;
    else throw res.msg;
  })
}

/**
 * 获取集抄数据
 * @author LXBsmile
 * @date 2019-12-12
 * @param {Number} id
 * @returns {Array}
 */
export function getAllData(id) {
  return axios.get(`/svg/device/realPaedata/${id}`).then(res => {
    if (res.code === 1) return res.data;
    else throw res.msg;
  })
}

/**
 * 获取集抄历史数据
 * @author LXBsmile
 * @date 2019-12-18
 * @param {Number, String} stationId
 * @param {Number} interval 1: 当天, 2: 当月, 3: 当年
 * @param {String} startTime 日期字符串
 * @returns {Object}
 */
export function getAllHis(stationId, interval, startTime) {
  const params = {
    stationId,
    interval,
    startTime
  }
  return axios.get('/plat/isp/queryHistoryDataPae', { params }).then(res => {
    if (res.code === 1) return res.data;
    else throw res.msg;
  })
}

export function exportReport(stationId, interval, startTime, excelVersion) {
  const params = {
    stationId,
    interval,
    startTime,
    excelVersion
  }
  return axios.get('/plat/isp/report/power/excel', { params, responseType: 'blob' }).then(res => {
    return res;
  })
}

export function getStationView(clientId, stationId) {
  const params = {
    stationId,
    clientId
  }
  return axios.get('/plat/index/viewstaion', { params }).then(res => {
    if (res.code === 1) return res.data;
    else throw res.msg;
  })
}

export function getStationAlarms(clientId, stationId, type = 1) {
  const params = {
    stationId,
    clientId,
    type
  }
  return axios.get('plat/index/viewWarns', { params }).then(res => {
    if (res.code === 1) return res.data;
    else throw res.msg;
  })
}
